﻿using System;

namespace NCql.Parser
{
    public static class StringConverter
    {
        public static string Convert(string s)
        {
            if (string.IsNullOrEmpty(s))
                return string.Empty;

            bool startsWithQuote = s.StartsWith("\"");
            bool endsWithQuote = s.EndsWith("\"");

            if ((startsWithQuote && !endsWithQuote) || (endsWithQuote && !startsWithQuote))
                throw new ArgumentException("Unbalanced Quotes in s:" + s);

            if (startsWithQuote)
            {
                s = s.Substring(1, s.Length - 2);
                s = s.Replace("\\\"", "\"");
            }
            return s;
        }
    }
}